package test.aat.ejinr.chkphone01;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

public class LT13099 {

	private static List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	private static long StartPhone = 13099999999L;

	public static void main(String[] args) {
		String s = HttpRequest.sendGet("http://211.103.170.153/kvs/getvuk", "k=LT13099");
		StartPhone = Long.parseLong(s);
		while (true) {
			System.out.println("start run ... "+StartPhone);
			try {
				// start  此为单线程
				if (list.size() > 1) {
					Map<String, Object> map = list.get(0);
					list.remove(0);
					final String ip = map.get("ip") + "";
					final String port = map.get("port") + "";
					final String phone = StartPhone + "";
					chkWrite(ip, port, phone);
					StartPhone--;
				} else {
					list = getProxy();
					HttpRequest.sendGet("http://211.103.170.153/kvs/setvuk", "k=LT13099&v=" + StartPhone);
				}
				// end
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	@SuppressWarnings("unchecked")
	public static List<Map<String, Object>> getProxy() {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		String s = HttpRequest.sendGet("http://dbapi.etuishou.cn:8888/DBapi/servlet/GetProxy", "protocols=http");
		Object o = JSONObject.parse(s);
		list = (List<Map<String, Object>>) o;
		return list;
	}

	// 代理验证手机号-金融账户
	// 写入API数据库
	public static void chkWrite(String ip, String port, String phone) {
		if (ChkTools.chkLTPhone(ip, port, phone)) {
			if (ChkTools.testHxw(ip, port, phone) || ChkTools.testThx(ip, port, phone)) {
				// API传给温珂
				try{
					HttpRequest.sendGet("http://211.103.170.153/kvs/addJarPhone", "p=" + phone + "&f=finance");
				}catch(Exception e){
					
				}
				
				// end
			}
			// end
			try{
				HttpRequest.sendGet("http://dbapi.etuishou.cn:8888/DBapi/servlet/SetMobileStatus", "mobile=" + phone);
			}catch(Exception e){
				
			}
			
			try{
				HttpRequest.sendGet("http://211.103.170.153/kvs/addJarPhone", "p=" + phone + "&f=10010");
			}catch(Exception e){
				
			}
			
		}
		// end
	}
	// end

}
